package wyu.controller;

import com.dto.Result;
import com.entity.Category;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;
import wyu.service.CategoryService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RefreshScope
@RequestMapping("/category")
public class CategoryController {
    @Resource
    CategoryService categoryService;
    @GetMapping("/getList")
    public Result getList(HttpServletRequest request){
        System.out.println(request.getSession().getAttribute("user"));
        return categoryService.getList();
    }
    @GetMapping("/admin/del")
    public Result categoryDel(@RequestParam("id")int id){
        System.out.println(id);
        return categoryService.categoryDel(id);
    }
    @GetMapping("/idUsed")
    public Result idUsed(@RequestParam("id")int id){
        return categoryService.idUsed(id);
    }
    @PostMapping("/admin/add")
    public Result categoryAdd(@RequestParam("id")int id,
                              @RequestParam("name")String name,
                              @Nullable @RequestParam("describe")String describe){
        return categoryService.categoryAdd(id,name,describe);
    }
    @GetMapping("/getbyid")
    public Category getbyid(@RequestParam("id")int id){
        return categoryService.getById(id);
    }
}
